﻿using System;
using System.Collections.Generic;
using Rabbit.Logic;
using RabbitShop.Code;
using Raven.Imports.Newtonsoft.Json;

namespace RabbitShop.UI
{
    public partial class CartView : System.Web.UI.Page
    {
        protected string uid = string.Empty;
        protected List<ShopCartViewItem> list;
        protected string cartJson = string.Empty;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies[Constant.CookieName] != null)
            {
                string id = Request.Cookies[Constant.CookieName].Values[Constant.CookieUid];
                if (string.IsNullOrEmpty(id)) Response.Redirect("UserLogon.aspx");
                uid = id;

                Customer customer = RabbitUse.GetCustomerById(Db.Store, uid);
                list = RabbitUse.GetShopCartView(Db.Store, customer);
                myRepeater.DataSource = list;
                myRepeater.DataBind();

                cartJson = JsonConvert.SerializeObject(customer.Cart);
            }
            else
            {
                Response.Redirect("UserLogon.aspx");
            }
        }
    }
}